/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package smartgrid;

import org.orm.PersistentException;
public class VariaveisSistemaProcessor {
	private int ID;
	
	private java.util.Date ultimoPovDia;
	
	private java.util.Date ultimoPovSemana;
	
	private java.util.Date ultimoPovMes;
	
	private String action="";
	
	public void setID(int value) {
		this.ID = value;
	}
	
	public int getID() {
		return ID;
	}
	
	public void setUltimoPovDia(java.util.Date value) {
		this.ultimoPovDia = value;
	}
	
	public java.util.Date getUltimoPovDia() {
		return ultimoPovDia;
	}
	
	public void setUltimoPovSemana(java.util.Date value) {
		this.ultimoPovSemana = value;
	}
	
	public java.util.Date getUltimoPovSemana() {
		return ultimoPovSemana;
	}
	
	public void setUltimoPovMes(java.util.Date value) {
		this.ultimoPovMes = value;
	}
	
	public java.util.Date getUltimoPovMes() {
		return ultimoPovMes;
	}
	
	public String getAction() {
		return action;
	}
	
	public void setAction(String action) {
		this.action = action;
	}
	
	public String process() {
		String result = "Unexcepted result";
		if (action.equals("search")) {
			smartgrid.VariaveisSistema _variaveisSistema = smartgrid.VariaveisSistema.loadVariaveisSistemaByORMID(getID());
			if (_variaveisSistema!= null) {
				copyFromBean(_variaveisSistema);
				result = "Search success";
			}
			else {
				result = "Search failed";
			}
		}
		else if(action.equals("insert"))  {
			try {
				smartgrid.VariaveisSistema _variaveisSistema = smartgrid.VariaveisSistema.createVariaveisSistema();
				copyToBean(_variaveisSistema);
				if (_variaveisSistema.save()) {
					result = "Insert success";
				}
				else {
					result = "Insert failed";
				}
			}
			catch (Exception e) {
				result = "Insert error: " + e.toString();
			}
		}
		else if (action.equals("update")) {
			smartgrid.VariaveisSistema _variaveisSistema= smartgrid.VariaveisSistema.loadVariaveisSistemaByORMID(getID());
			if (_variaveisSistema != null) {
				copyToBean(_variaveisSistema);
				if (_variaveisSistema.save()) {
					result = "Update success";
				}
				 else {
					result = "Update failed";
				}
			}
			 else  {
				result = "Update failed";
			}
			
		}
		else if (action.equals("delete")) {
			smartgrid.VariaveisSistema _variaveisSistema = smartgrid.VariaveisSistema.loadVariaveisSistemaByORMID(getID());
			if (_variaveisSistema != null && _variaveisSistema.delete()) {
				result = "Delete success";
			}
			else {
				result = "Delete failed";
			}
		}
		else if (action.equals("")) {
			result = "";
		}
		action = "";
		return result;
	}
	
	private void copyFromBean(smartgrid.VariaveisSistema _variaveisSistema) {
		setUltimoPovDia(_variaveisSistema.getUltimoPovDia());
		setUltimoPovSemana(_variaveisSistema.getUltimoPovSemana());
		setUltimoPovMes(_variaveisSistema.getUltimoPovMes());
		setID(_variaveisSistema.getORMID());
	}
	
	private void copyToBean(smartgrid.VariaveisSistema _variaveisSistema) {
		_variaveisSistema.setUltimoPovDia(getUltimoPovDia());
		_variaveisSistema.setUltimoPovSemana(getUltimoPovSemana());
		_variaveisSistema.setUltimoPovMes(getUltimoPovMes());
	}
	
}

